/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Modelo.Controler;

import Model.Beans.User;
import Model.Servicios.UserSrv;
import Model.Utilities.Constantes.TypeUser;
import com.opensymphony.xwork2.ActionSupport;
import java.util.Map;
import org.apache.struts2.interceptor.SessionAware;

/**
 *
 * @author John Mex
 */
public class UserLoginAction extends ActionSupport implements SessionAware{
    
    
    private Map<String,User> session;
    private String username;
    private String password;
    UserSrv  userSrv = new UserSrv();
    
    public String login(){
        User user = userSrv.getUser(username, password);
        if(user!=null){
            session.put("user", user);
            System.out.println(user.getType());
            if(user.getType().compareTo(TypeUser.institution)==0){
                return "institution";
            }
            if(user.getType().compareTo(TypeUser.manager)==0){
                return "admin";
            }
            if(user.getType().compareTo(TypeUser.student)==0){
                return "student";
            }
        }
        
        return "error";
    }

    /**
     * @return the session
     */
    public Map getSession() {
        return session;
    }

    /**
     * @param session the session to set
     */
    public void setSession(Map session) {
        this.session = session;
    }

    /**
     * @return the username
     */
    public String getUsername() {
        return username;
    }

    /**
     * @param username the username to set
     */
    public void setUsername(String username) {
        this.username = username;
    }

    /**
     * @return the password
     */
    public String getPassword() {
        return password;
    }

    /**
     * @param password the password to set
     */
    public void setPassword(String password) {
        this.password = password;
    }
    
}
